﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Media.Media3D;
using HelixToolkit.Wpf;

namespace GameBoard
{
    static class ObjectFileReader
    {
        internal static ModelVisual3D MakeModelVisual3DFromObjectFile(string modelPath, Material frontMaterial, bool overrideMaterialFile)
        {
            bool useMaterialFile = !overrideMaterialFile;
            var objReader = new ObjReader();
            var group = objReader.Read(modelPath);
            ModelVisual3D myModelVisual3D = new ModelVisual3D();
            myModelVisual3D.Content = group;
            if (useMaterialFile)
            {
                string materialFile = modelPath.Replace(".obj", ".mtl");
                useMaterialFile = File.Exists(materialFile);

            }
            if (!useMaterialFile)
            {
                foreach (GeometryModel3D geometry in (myModelVisual3D.Content as Model3DGroup).Children)
                {
                    geometry.Material = frontMaterial;
                }
            }
            else
            {
                
            }
            return myModelVisual3D;
        }
    }
}
